package com.haochang.chunkvod.controller.activity.hostess;

import java.util.ArrayList;
import java.util.List;

import com.haochang.base.BaseActivity;
import com.haochang.chunkvod.R;
import com.haochang.chunkvod.app.utils.CollectionUtils;
import com.haochang.chunkvod.controller.adapter.hostess.ReserveAdapter;
import com.haochang.chunkvod.model.hostess.HostessData;
import com.haochang.chunkvod.model.hostess.HostessInfo;
import com.haochang.chunkvod.view.thirdparty.PullToRefresh.PullToRefreshBase;
import com.haochang.chunkvod.view.thirdparty.PullToRefresh.PullToRefreshGridView;
import com.haochang.chunkvod.view.vod.popupWindow.VodPopWindow;
import com.haochang.chunkvod.view.vod.title.TitleView;

import android.widget.GridView;
import android.widget.ImageView;

/**
 *     @author Yangjie
 *     className ReserveActivity
 *     created at  2016/8/23  18:08
 *     咨客 预定信息
 */
public class ReserveRoomActivity extends BaseActivity
{

	private TitleView titleView;
	private PullToRefreshGridView mGridView;

	private ReserveAdapter adapter;
	private HostessData reserveData;
	private List<HostessInfo> reverseRoomInfoList = new ArrayList<HostessInfo>();

	@Override
	public void receiveParam()
	{
	}

	@Override
	public void initData()
	{
		reserveData = new HostessData(ReserveRoomActivity.this);
	}

	@Override
	public void initViews()
	{
		setContentView(R.layout.activity_reserve_room);
		titleView = (TitleView) findViewById(R.id.titleView);
		mGridView = (PullToRefreshGridView) findViewById(R.id.app_grid);
		mGridView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);

	}

	@Override
	public void initViewsData() {
		titleView.setTitle(R.string.reverse).setTitleOnClickListener(new TitleView.ITitleOnClickListener()
		{
			@Override
			public void onBackClick()
			{
				finish();
				animRightToLeft();
			}

			@Override
			public void onDoneClick()
			{
				List<String> list = new ArrayList<String>();
				list.add("回到首页");
				list.add("修改密码");
				list.add("退出登录");
				int location[] = new int[2];
				ImageView img = (ImageView) titleView.findViewById(R.id.img_operates);
				img.getLocationOnScreen(location);
				int x = location[0];
				final VodPopWindow pop = new VodPopWindow(ReserveRoomActivity.this, list);
				pop.showPopupWindow(titleView, x);
				pop.setPopWindowListListener(new VodPopWindow.OnPopWindowListListener()
				{
					@Override
					public void onSelectItem(int position)
					{
						switch (position)
						{
							case 0:
								backToHome();
								break;
							case 1:
								goToPasswordModify();
								break;
							case 2:
								loginOut();
								break;

							default:
								break;
						}
					}
				});
			}
		});
		mGridView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<GridView>()
		{
			@Override
			public void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView)
			{
				getReserveRoomList(false);
			}

			@Override
			public void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView)
			{

			}
		});
		adapter = new ReserveAdapter(ReserveRoomActivity.this, R.layout.item_reserve_room_layout, reverseRoomInfoList);
		mGridView.setAdapter(adapter);
	}
	@Override
	public void onResume()
	{
		super.onResume();
		getReserveRoomList(false);
	}
	/**
	 * 获取房间信息数据
	 *
	 * @param isLoading 网络请求时是否转圈
	 */
	@SuppressWarnings("unchecked")
	public void getReserveRoomList(boolean isLoading)
	{
		reserveData.requestReserveRoomStatusList(isLoading, new HostessData.ResultResponseList<HostessInfo>()
		{
			@Override
			public void onRequestSuccess(List<HostessInfo> list)
			{
				mGridView.onRefreshComplete();
				if (!CollectionUtils.isEmpty(list))
				{
					reverseRoomInfoList.clear();
					reverseRoomInfoList.addAll(list);
				} else
				{
					reverseRoomInfoList.clear();
				}
				adapter.replaceAll(reverseRoomInfoList);
			}

			@Override
			public void onFail(int errno, String errMsg)
			{
				mGridView.onRefreshComplete();
			}
		});
	}

}
